<?php
	defined('_JEXEC') or die('Restricted access');
	
	$num = $params->get('numpro',6);
	
	$db = JFactory::getDBO();
	$query = "SELECT p.* FROM #__pr_product p LEFT JOIN #__auction a ON p.id = a.product_id WHERE ((p.type = 3 OR p.type = 2) AND p.bought = 0 AND p.published = 1) OR (p.type = 1 AND p.approve = 1 AND a.closed = 0 AND a.published = 1) ORDER BY RAND() LIMIT 0,".$num;
	$db->setQuery($query);
	$images = $db->loadObjectList();
	if($_GET['Itemid'] == 1) {
		$class = 'p15t';
		$itemid = 1;
	} else {
	   $itemid = 0;
		$class = 'p80t';
	}
?>
<div class="<?php echo $class;?>">
    <div class="boder_b_d tex_up font15 red_color"><strong>Biler til salg</strong></div>

    <!-- begin: #List Images -->
    <div class="nav-btn-left float_left"><a href="javascript:;" class="prev"><img src="templates/tpl_automobil/images/icon_prev.png" alt="" /></a></div>
    <script language="javascript">
    $(function(){
        $("#mycarousel").jCarouselLite({
            btnNext: ".next",
            btnPrev: ".prev",
            visible : <?php if(count($images) > 2) echo 4; else echo 2;?>,
            scroll: 1,
            <?php if($itemid == 1) {?> auto: 2000, 
            speed: 500
			<?php } else {?>
			speed: 1000
			<?php }?>
        });
            
    });	
    </script>
    
    <div class="w938 float_left m5l m15t" id="mycarousel">
        <ul class="list_img1">
            <?php foreach($images as $img){
                if($img->type == 2){
					$title = "BILER TIL SALG";
					$type = "2-biler-til-salg";
					$link = "index.php?option=com_ecommerce&view=detail&type=".$type."&id=".$img->id."-".$img->alias;
				}
                if($img->type == 3){
					$title = "KOMMENDE TVANGSAUKTION";
					$type = "3-kommende-tvangsauktion";
					$link = "index.php?option=com_ecommerce&view=detail&type=".$type."&id=".$img->id."-".$img->alias;
				}
				if($img->type == 1){
					$title = "KATALOG";
					$query = "SELECT id FROM #__auction WHERE product_id = ".$img->id;
					$db->setQuery($query);
					$auc_id = $db->loadResult();
					$link = "index.php?option=com_auction&view=list&auc_id=".$auc_id."&Itemid=10";
				}
            ?>
            <li><p><a title="" href="<?php echo $link;?>"><?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$img->image."&w=217&h=97&zc=1' border='0' title='".$img->model."' alt='".$img->model ."' />";?></a></p>
               <div class="wrapper-tooltip">            
                    <div class="tooltip-top"></div>
                    <div class="tooltip-content">
                        <h6><?php echo $title;?></h6><?php echo $img->model;?>
                    </div>
                    <div class="tooltip-bottom"></div>
                </div>
            </li>
            <?php }?>
         </ul>
    </div>

    <div class="nav-btn-right float_right"><a href="javascript:;" class="next"><img src="templates/tpl_automobil/images/icon_next.png" alt="" /></a></div>
    <div class="cb"></div>
    <!-- End: #List Images -->
</div>